import { searchInfo } from '../../apis/index'
// pages/search/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    city: '',
    name: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow(options) {

  },

  // 点击去单项的详情页面
  goProdctDetail(e) {
    const { id } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/productDetail/index?itemId=' + id,
    })
  },
  
  // 用户输入值
  searchInput(e) {
    this.setData({
      name: e.detail.value,
      city: wx.getStorageSync('cityName') || '上海'
    })
    this.searchFood()
  },

  // 模糊搜索
  async searchFood() {
    const { city, name } = this.data
    const res = await searchInfo(city, name)
    if (res.status === 200) {
      this.setData({
        list: res.data
      })
    }
  }
})